package com.itheima.service.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.UserDao;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import com.itheima.until.CheckResult;
import com.itheima.until.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;

@Service(interfaceClass = UserService.class,protocol = "dubbo")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public String login(User user) {
        User userAndPassword = userDao.getUserAndPassword(user);
        if(userAndPassword ==null){
            return null;

        }
        String jwt = JwtUtils.createJWT(user.getId(), user.getName());
        return jwt;

    }

    @Override
    public boolean validateJwt(String jwt) {
        CheckResult checkResult = JwtUtils.validateJWT(jwt);
        boolean success = checkResult.isSuccess();
        return success;
    }
}
